<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="formModel">
        <el-form-item class="no-warn-item" label="物料编码:" prop="materialNo">
          <el-input
            v-model="formModel.materialNo"
            class="filter-item "
            clearable
          />
        </el-form-item>
        <el-form-item class="no-warn-item" label="物料组:" prop="materialTypeKey">
          <hey-select v-model="formModel.materialTypeKey" :disabled="disabledMaterialType" clcd="key_material_type" />
        </el-form-item>
        <el-form-item class="no-warn-item" label="产品组:" prop="productTypeKey">
          <hey-select v-model="formModel.productTypeKey" clcd="key_product_type" />
        </el-form-item>
        <el-form-item class="no-warn-item" label="状态:" prop="status">
          <hey-select v-model="formModel.status" clcd="is_effective_cd" disabled />
        </el-form-item>
        <el-row class="submit-area">
          <el-col :span="24">
            <el-button type="primary" plain @click="queryList">查询</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <hey-table ref="table" @row-click="handleRowClick" :columns="columns" :is-radio="true">

    </hey-table>
    <el-row class="submit-area">
      <el-col :span="24">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="handleSubmit()">确定</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  export default {
    name: 'MaterialDataDialog',
    props: ['pageType', 'editData'],
    data() {
      return {
        chooseData:{},
        disabledMaterialType :false,
        formModel: {
          materialNo: '',
          materialTypeKey: '',
          productTypeKey: '',
          status: '1'
        },
        columns: [
          {title: '物料编码', key: 'materialNo'},
          {title: '物料描述', key: 'materialDesc'},
          {title: '单位', key: 'unit'},
          {title: '物料组', key: 'materialTypeKey',clcd: 'key_material_type'},
          {title: '产品组', key: 'productTypeKey',clcd: 'key_product_type'},
          {title: '状态', key: 'status', clcd: 'is_effective_cd'},
          {title: '创建时间', key: 'createTime'},
          {title: '创建人', key: 'createUsername'},
          {title: '最后修改时间', key: 'lastUpdateTime'},
          {title: '最后修改人', key: 'lastUpdateUsername'}
        ],
        rules: {
        }
      }
    },
    computed: {

    },
    mounted() {
      const {editData} = this
      if (editData.materialTypeKey) {
        this.formModel.materialTypeKey = editData.materialTypeKey
        this.disabledMaterialType = true
      }
    },
    methods: {
      handleSubmit() {
        if(Object.keys(this.chooseData).length==0){
          this.$warn('请单击选中一条数据!')
          return false
        }
        this.$emit('queryMaterialDataSuc', this.chooseData)
        this.closeDialog()
      },
      handleRowClick(row){
        this.chooseData = row
      },
      queryList() {
        this.$refs.table.query('/materialData/page', this.formModel, '', false)
      },
      closeDialog() {
        this.$parent.$emit('update:visible', false)
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
